/*
 * Tf: a unit test framework for C
 * Copyright (C) 2012 zrezek at gmail.com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3.0 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#include "money.h"
#include <string.h>
#include <assert.h>

void money_init(money_t* money, const char* currency, double ammount)
{
    assert(money && currency);

    money->currency = currency;
    money->ammount = ammount;
}

const char* money_get_currency(money_t* money)
{
    assert(money);

    return money->currency;
}

double money_get_ammount(money_t* money)
{
    assert(money);

    return money->ammount;
}

int money_add(money_t* dst, const money_t* m1, const money_t* m2)
{
    assert(dst && m1 && m2);

    if (!strcmp(m1->currency, m2->currency))
    {
        dst->currency = m1->currency;
        dst->ammount = m1->ammount + m2->ammount;
        return 1;
    }
    return 0;
}

int money_cmp(const money_t* m1, const money_t* m2)
{
    assert(m1 && m2);

    if (!strcmp(m1->currency, m2->currency))
    {
        return !(m1->ammount == m2->ammount);
    }
    return 1;
}
